package com.yorkfeng.blemulti.Utils;

import android.app.ActivityManager;
import android.content.Context;
import android.util.Log;

import java.util.List;

/**
 * Created by yorkfeng on 16/11/14.
 */
public class Constants {
    public static final String LAST_CONNECTED_ADDRESS = "last_connected_address";
    public static final String LAST_CONNECTED_ADDRESS_L = "last_connected_address_l";
    public static final String LAST_CONNECTED_ADDRESS_R = "last_connected_address_r";
    public static final String CONFIG_FILE_NAME = "ble_demo_ore_config";
    public static final String SEARCH_ACTIVITY = "com.yorkfeng.bledemoore.activity.BluetoothSearchActivity";
    public static final String MAIN_ACTIVITY = "com.yorkfeng.bledemoore.activity.MainActivity";
    public static final String EXTRAS_DEVICE_NAME = "DEVICE_NAME";
    public static final String EXTRAS_DEVICE_ADDRESS = "DEVICE_ADDRESS";
    // read&write characteristic
    public static final String UUID_SEND_CHARACTERISTIC = "0000ffe9-0000-1000-8000-00805f9b34fb";
    public static final String UUID_READ_CHARACTERISTIC = "0000ffe4-0000-1000-8000-00805f9b34fb";


    public static boolean isTopActivity(Context context, String activityName) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(1);
        for (ActivityManager.RunningTaskInfo task : runningTasks) {
            Log.d("Constants", task.topActivity.getClassName());
            if (task.topActivity.getClassName().equals(activityName)) {
                return true;
            }
        }
        return false;
    }

    public static byte[] getBooleanArray(byte b) {
        byte[] array = new byte[8];
        for (int i = 7; i >= 0; i--) {
            array[i] = (byte) (b & 1);
            b = (byte) (b >> 1);
        }
        return array;
    }

}
